/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package library.gui;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import library.Item;

/**
 *
 * @author ryan
 */
public class AddItemPopup extends JFrame{
    public AddItemPopup(final InventoryPanel p){
        super();
        final JLabel lblName = new JLabel("Name");
        final JTextField name = new JTextField();
        final JTextArea description = new JTextArea();
        description.setSize(80, 60);
        final JComboBox type = new JComboBox();
        for(Item.Type t: Item.Type.values()){
            type.addItem(t);
        }
        JButton ok = new JButton("ok");
        ok.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                if(!name.getText().isEmpty()){
                    Item item = new Item(name.getText(), (Item.Type)type.getSelectedItem(), description.getText());
                      p.addItem(item);
                      AddItemPopup.this.dispose();
                }else{
                    JOptionPane.showMessageDialog(null,"Name cannot be blank","Name error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
     
        
        GridLayout layout = new GridLayout(0, 1);
        this.getContentPane().setLayout(layout);
        this.add(lblName);
        this.add(name);
        this.add(type);
        this.add(description);
        this.add(ok);
        this.setLocation(500, 400);
        this.pack();
        this.setVisible(true);
    }
}